package tech.aister.day02;

public class StringDemo {
    public static void main(String[] args) {
        //1. 串池
        String a = "admin";
        String b = "admin";
        System.out.println(a == b);//true

        //x指向的是堆里面的"abc"
        String x = new String("abc");
        String y = new String("abc");
        System.out.println(x == y);//false

        System.out.println(x.equals(y));//true

        String z = "abc";
        System.out.println(x == z);//false

        //让x强制指向串池中的"abc";
        System.out.println(x.intern() == z);//true

        String o1 = "a";
        String o2 = o1 + "b";// 底层JVM指令 -> new StringBuilder对象   <- o2

        String o4 = "a" + "b";// "ab"整体 -> ldc
        String o3 = "ab";
        System.out.println(o2 == o3);//false
        System.out.println(o4 == o3);//true

        final String f = "a";//final=>不可变的
        String f2 = f + "b"; // "ab" => 常量池
        System.out.println(o3 == f2);//true

        //API方法
        String s1 = "abcd".substring(1);
        System.out.println(s1);
        System.out.println(s1 == "bcd");//false

        char result = "abc".charAt(1);
        System.out.println(result);
    }

}
